<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">

</head>
<body>
<template id="add-item-template">
    <div class="input-group">
        <input @keyup.enter="addItem" v-model="newItem" placeholder="add list item" type="text" class="form-control">
        <span class="input-group-btn">
            <button @click="addItem" class="btn btn-default" type="button">Add!</button>
        </span>
    </div>
</template>

<template id="item-template">
    <li :class="{'removed':item.checked}">
        <div class="checkbox">
            <label>
                <input type="checkbox" v-model="item.checked">{{item.text}}
            </label>
        </div>
    </li>
</template>

<template id="items-template">
    <ul>
        <item-component v-for="item in items" :item="item"></item-component>
    </ul>
</template>

<template id="change-title-template">
    <div>
        <em>Change the title of your shopping list here</em>
        <input v-bind:value="value" v-on:input="onInput">
    </div>
</template>

<div id="app" class="container">
    <h2>{{title}}</h2>
    <add-item-component></add-item-component>
    <items-component :items="items"></items-component>
    <div class="footer">
        <change-title-component v-model="title"></change-title-component>
    </div>
</div>

<script src="https://cdn.bootcss.com/vue/2.6.10/vue.js"></script>
<script>
    var data = {
        items: [{ text: 'Bananas', checked: true }, { text: 'Apples', checked: false }],
        title: 'gouwuqingdan'
    };

    //add item component
    Vue.component('add-item-component', {
        template: '#add-item-template',
        data: function () {
            return {
                newItem: ''
            }
        },
        methods:{
            addItem: function () {
                var text;

                text = this.newItem.trim();
                if (text) {
                    data.items.push({
                        text: text,
                        checked: false
                    });
                    this.newItem = "";
                }
            }
        }
    });
    //item component
    Vue.component('item-component', {
        template: '#item-template',
        props: ['item']
    });
    //items component
    Vue.component('items-component', {
        template: '#items-template',
        props: ['items']
    });
    //change title component
    Vue.component('change-title-component', {
        template: '#change-title-template',
        props: ['value'],
        methods: {
            onInput: function (event) {
                this.$emit('input', event.target.value)
            }
        }
    });

    new Vue({
        el: '#app',
        data: data,
        methods: {

        }
    });
</script>
</body>
</html>